package defiant;

import static defiant.common.tools.Logger.log;
import static defiant.common.tools.SysProperties.DEBUG;
import static defiant.common.tools.SysProperties.WEB_SERVER_PORT;

import java.net.Socket;

import defiant.common.tools.Console;
import defiant.common.tools.SysProperties;

public class Start {

	protected static void init() {
		SysProperties.initialize();
	}
	
	protected static boolean isRunning() {
		try {
			Socket serverSok = new Socket("127.0.0.1", WEB_SERVER_PORT);
			serverSok.close();
			
			if (DEBUG) log("An instance is already running");
			return true;
		} catch (Exception e) {
			// ignore
		} 
		
		return false;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// call initialize for resource util classes
		init();

		// start session 
		if (!isRunning()) {
			new Console().run();
		}
	
	}

}
